home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / system / serialxx.zip / SERIAL.HPP < prev    next >
C/C++ Source or Header  |  1989-12-19  |  4KB  |  121 lines

  1. // Copyright Prototronics
  2. // Totem Lake P.O. 8117
  3. // Kirkland, Washington 98034
  4.  
  5. // Joe Huffman 
  6. // September 16, 1989
  7. // (206) 820-1972
  8.  
  9.  
  10. #ifndef SERIAL_HPP
  11. #define SERIAL_HPP 1
  12.  
  13. // Serial port code.
  14.  
  15. typedef enum serial_port_number_enum 
  16. {
  17.   SERIAL_COM1,
  18.   SERIAL_COM2,
  19.   SERIAL_LAST_PORT
  20. } serial_port_number;
  21.  
  22. typedef enum serial_baud_enum
  23. { // Numbers correspond to the divisor for the UART.
  24.   SERIAL_50 = 2304, SERIAL_110 = 1047, SERIAL_300 = 384, 
  25.   SERIAL_1200 = 96, SERIAL_2400 = 48, SERIAL_4800 = 24, SERIAL_9600 = 12
  26. } serial_baud;
  27.  
  28. struct serial_port_buffer
  29. {
  30.   unsigned char far *send_buffer, far *send_head_p, far *send_tail_p;
  31.   unsigned char far *receive_buffer, far *receive_head_p, far *receive_tail_p;
  32.   volatile unsigned int send_bytes, receive_bytes;
  33.   unsigned int buf_size;
  34.   long int old_int_vec;       // Used in the asm code.
  35.   unsigned int com_port_addr; // Used in the asm code.
  36.   unsigned char int_number;   // Used in the asm code.
  37.   unsigned char eoi_indicator;// Used in the asm code.
  38. };
  39.  
  40. struct serial_port_registers
  41. {
  42.   unsigned int divisor;
  43.   unsigned char line_cntr_reg, intr_enable_reg, modem_reg, enable_8259_mask;
  44. };
  45.  
  46. class serial
  47. {
  48. // These are the currently active buffer pointers.
  49.   static struct serial_port_buffer serial_buffers [SERIAL_LAST_PORT];
  50.  
  51.   int status_val;
  52.   serial_port_number port;
  53.   unsigned int modem_port_addr;
  54.   struct serial_port_buffer old_buffer; // Watch it carefully, these are NOT 
  55.                                         // the currently active buffers.
  56.                                         // It is the last active ones.
  57.   struct serial_port_registers old_registers;  // Last active register values.
  58.  
  59. void port_init (void);
  60. void port_term (void);
  61.  
  62. public:
  63. serial(serial_port_number port_num,unsigned int size_of_buffer, serial_baud b);
  64. ~serial (void);
  65.  
  66. /****************************************************************************
  67. Return 0 if the everything is okay.  Return ASCII string of error message if
  68. there is a problem.  Like not enough memory for the buffers, whatever.
  69. September 17, 1989
  70. ****************************************************************************/
  71. const char *status (void);
  72.  
  73. /****************************************************************************
  74. Output a byte to the serial port.  Returns the number bytes in the output 
  75. buffer after this byte is put in. 
  76. September 16, 1989
  77. ****************************************************************************/
  78. unsigned int put (unsigned char b);
  79.  
  80. /****************************************************************************
  81. Input a byte from the serial port.  Returns the number of bytes in the input
  82. buffer after this byte is taken out.  Returns ~0 if there were no bytes in the 
  83. buffer.
  84. September 16, 1989
  85. ****************************************************************************/
  86. unsigned int get (unsigned char &b);
  87.  
  88. /****************************************************************************
  89. Get the number of bytes remaining in the receive buffer.
  90. September 16, 1989
  91. ****************************************************************************/
  92. unsigned int received_bytes_waiting(void);
  93.  
  94. /****************************************************************************
  95. Get the number of bytes remaining in the send buffer.
  96. September 16, 1989
  97. ****************************************************************************/
  98. unsigned int send_bytes_waiting(void);
  99.  
  100. /****************************************************************************
  101. Set the baud rate.
  102. September 16, 1989
  103. ****************************************************************************/
  104. void baud (serial_baud b);
  105.  
  106. /****************************************************************************
  107. Clear the receive buffer.  All data in the receive buffer is lost.
  108. September 21, 1989
  109. ****************************************************************************/
  110. void receive_clear (void);
  111.  
  112. /****************************************************************************
  113. Clear the transmit buffer.  All data in the transmit buffer is lost.
  114. September 21, 1989
  115. ****************************************************************************/
  116. void transmit_clear (void);
  117.  
  118. };
  119.  
  120. #endif // SERIAL_HPP
  121.